﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FinYear.aspx.cs" Inherits="Main_Master_FinYear"
    Culture="en-GB" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="CalendarExtenderPlus" Namespace="AjaxControlToolkitPlus" TagPrefix="advancedCalender" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Financial Year</title>
    <link href="../../Styles/accounts.css" rel="Stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
    function Finyear(lbldate)
    {        
        document.getElementById("TxtCurrentDate").value = document.getElementById(lbldate).innerHTML;
    }
    function CloseWindow() {        
        window.opener.parent.location.reload();// = "../../Menu/Footer.aspx";
        self.close();
    }

    function ConfirmNewYear(FinYear) {

        var check = confirm('Do You want to Create new \n Financial Year' + FinYear + '-' + (parseFloat(FinYear) + 1));
        if (check) {
            document.getElementById("hidConfirm").value = '1';
        }
        else {
            document.getElementById("hidConfirm").value = '0';
        }
    }
    function CheckValidDate(id) {
        var dt = '';
        dt = document.getElementById(id).value;           
        if (dt != '') {
            var arr = dt.toString().split('/');
            var fin_Year = '';
            if (parseFloat(arr[1]) >= 4 && parseFloat(arr[1]) <= 12) {
                fin_Year = arr[2];
            }
            else if (parseFloat(arr[1]) >= 1 && parseFloat(arr[1]) < 3) {
                fin_Year = (parseFloat(arr[2]) - 1);
            }
            if (fin_Year != '') {
                var gridView = document.getElementById("Grdfinyear");
                var inputs = gridView.getElementsByTagName("input");
                var maxVal = 0;
                var minVal = 0;                
                var tempArray = new Array(); 
                for (var i = 0; i < inputs.length; i++) {
                    if (inputs[i].type == "hidden") {
                        tempArray[i] = parseFloat(inputs[i].value);                      
                    }
                }
                maxVal = tempArray[0];
                minVal = tempArray[0];
                for (var i = 0; i < tempArray.length; i++) {
                    if (tempArray[i] > maxVal) {
                        maxVal = tempArray[i];
                    }
                    if (tempArray[i] < minVal) {
                        minVal = tempArray[i];
                    }                    
                }                
                if ((parseFloat(maxVal) + 1) == parseFloat(fin_Year)) {
                    var ok = confirm('Do you want create new \n Financial Year ' + fin_Year + '-' + (parseFloat(fin_Year) + 1));
                    if (ok) {
                        document.getElementById("hidConfirm").value = '1';
                        document.getElementById("btnCreatefinyear").click();
                    }
                    else {
                        document.getElementById("hidConfirm").value = '0';
                        document.getElementById("TxtCurrentDate").value = document.getElementById("hidCurrentDate").value;
                    }
                }
                else if (parseFloat(fin_Year) > (parseFloat(maxVal) + 1)) {
                    alert('Invalid Date');
                    document.getElementById("TxtCurrentDate").value = document.getElementById("hidCurrentDate").value;
                }
                else if (parseFloat(fin_Year) < parseFloat(minVal)) {
                alert('Financial Year Can not  \n Less Than ' + minVal + '-' + (parseFloat(minVal) + 1));
                    document.getElementById("TxtCurrentDate").value = document.getElementById("hidCurrentDate").value;
                }
            }
        }
        return true;
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <%--<asp:UpdateProgress DynamicLayout="false" ID="UpdProgress" runat="server">
            <ProgressTemplate>
                <div align="center">
                    <img src="../../../Images/ajax-loader.gif" /></div>
            </ProgressTemplate>
        </asp:UpdateProgress>  --%>     
        <div style="text-align: center; width: 50%; margin-left: 22%; margin-right: 25%">
            <asp:Label ID="lblMsg" runat="server" Font-Bold="true"></asp:Label>
            <asp:HiddenField ID="hidConfirm" runat="server" Value="0" />
            <asp:HiddenField ID="hidCurrentDate" runat="server" />
            <asp:HiddenField ID="hidCurrentFinyear" runat="server" />
        </div>      
        
            <div style="width: 90%; margin-left: 5%; margin-right: 5%; margin-top:15px;">
                <table class="tablecontent" style="width: 99%;">
                    <tr>
                        <td colspan="2" class="headtd">
                            Set Financial year/Current Date
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Current Date <span class="required">*</span>
                        </td>
                        <td>
                              <asp:TextBox ID="TxtCurrentDate" runat="server" CssClass="inputnumber" onchange="CheckValidDate(this.id);"></asp:TextBox>
                            <asp:ImageButton ID="ImgBtnCurrentDate" runat="server" ImageUrl="~/Images/calendar.gif" />
                            <advancedcalender:calendarextenderplus id="CalFrom" runat="server" popupbuttonid="ImgBtnCurrentDate"
                                format="dd/MM/yyyy" targetcontrolid="TxtCurrentDate">
                            </advancedcalender:calendarextenderplus>
                            <%--<ajaxToolkit:CalendarExtender ID="CalExtTxtCurrentDate" runat="server" TargetControlID="TxtCurrentDate"
                                PopupButtonID="ImgBtnCurrentDate" Format="dd/MM/yyyy" Enabled="True" />--%>
                            <%--<ajaxToolkit:MaskedEditExtender ID="LuxuryDateMask" runat="server" CultureName="en-GB"
                                Enabled="True" TargetControlID="TxtCurrentDate" MaskType="Date" ErrorTooltipEnabled="True"
                                Mask="99/99/9999">
                            </ajaxToolkit:MaskedEditExtender>
                            <ajaxToolkit:MaskedEditValidator ID="LuxuryDateValmask" runat="server" ControlExtender="LuxuryDateMask"
                                ControlToValidate="TxtCurrentDate" EmptyValueMessage="Date is Required" InvalidValueMessage="Date is Invalid"
                                Display="Dynamic" EmptyValueBlurredText="*" ErrorMessage="AccountStartValmask" />--%>
                            <asp:RequiredFieldValidator ID="RfvTxtCurrentDate" runat="server" ControlToValidate="TxtCurrentDate" ErrorMessage="*"></asp:RequiredFieldValidator>    
                           
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div style="width: 95%; margin-right: 5%;">
                                <asp:GridView ID="Grdfinyear" CssClass="gridview" RowStyle-CssClass="gridviewitem"
                                    EmptyDataText="No Record Exist!" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="gridview_alternate"
                                    EmptyDataRowStyle-CssClass="emptyrow" AutoGenerateColumns="false" Width="100%"
                                    DataKeyNames="FinYear" runat="server" OnRowDataBound="Grdfinyear_RowDataBound">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Date">
                                            <ItemTemplate>
                                                <asp:Label ID="LblFinDate" runat="server" Text='<%#string.Format("{0:dd/MM/yyyy}", Eval("FinDate"))%>' ></asp:Label>
                                                <asp:HiddenField ID="hidFinYear" runat="server" Value='<%#Eval("FinYear")%>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <%--<asp:BoundField DataField="FinDate" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" />--%>
                                        <asp:BoundField DataField="Fin_Year" HeaderText="Financial Year" />
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>    
                            <asp:Button ID="btnCreatefinyear" runat="server" style="display:none;" OnClick="btnCreatefinyear_Click" />
                        </td>
                        <td>
                            <asp:Button ID="Accept" runat="server" Text="Accept" CssClass="button" OnClick="btnSave_Click" />
                            <asp:Button ID="Close" runat="server" Text="Close" CssClass="button" OnClientClick="CloseWindow();" />
                        </td>
                    </tr>
                </table>
            </div>       
    </div>
    </form>
</body>
</html>
